package com.oozol.lieluyun.utils;

import java.awt.geom.Point2D;
import java.util.Objects;

public class BeansUtils {
   private static final double EARTH_RADIUS = 6371393.0;

   public static String getPrintSize(long size, int base) {
      if (Objects.equals(base, 0)) {
         base = 1024;
      }

      if (size < (long)base) {
         return size + "B";
      } else {
         size /= (long)base;
         if (size < (long)base) {
            return size + "KB";
         } else {
            size /= (long)base;
            if (size < (long)base) {
               size *= 100L;
               return size / 100L + "." + size % 100L + "MB";
            } else {
               size = size * 100L / (long)base;
               return size / 100L + "." + size % 100L + "GB";
            }
         }
      }
   }

   public static double getDistance(Point2D pointA, Point2D pointB) {
      double radiansAX = Math.toRadians(pointA.getX());
      double radiansAY = Math.toRadians(pointA.getY());
      double radiansBX = Math.toRadians(pointB.getX());
      double radiansBY = Math.toRadians(pointB.getY());
      double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX) + Math.sin(radiansAY) * Math.sin(radiansBY);
      double acos = Math.acos(cos);
      return 6371393.0 * acos;
   }
}
